package com.zlx.guguanjia.mapper.provider;

import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @Author 周罗校
 * @Description
 * @ClassName SysResourceSqlProvider
 * @date 2020.11.06 17:31:01
 * 该版权归周罗校所有，最终解释权以官方为准
 */
public class SysResourceSqlProvider {
    public String selectMenuSources(Map<String,Object> map){
        StringBuilder sb = new StringBuilder();
//        sb.append("SELECT sre.*,psre.`name` parent_name FROM sys_resource sre, sys_resource psre  " +
//                "WHERE " +
//                "sre.del_flag =0  ");
//        if (map.containsKey("pid")&& !StringUtils.isEmpty(map.get("pid"))){
//            sb.append("AND sre.parent_id = #{pid} ");
//        }
//        if (map.containsKey("name")&& !StringUtils.isEmpty(map.get("name"))){
//            sb.append("AND sre.`name` LIKE CONCAT('%',#{name},'%') ");
//        }
//        sb.append("AND sre.parent_id = psre.id ");
//        sb.append("ORDER BY sre.sort");
        sb.append("SELECT DISTINCT sre.*,psre.`name` parent_name FROM sys_resource sre " +
                "LEFT JOIN sys_resource psre ON " +
                "sre.parent_id = psre.id " +
                "WHERE " +
                "sre.del_flag =0 ");
        if (map.containsKey("pid")&& !StringUtils.isEmpty(map.get("pid"))){
            sb.append("AND sre.parent_id = #{pid} OR sre.id = #{pid} ");
        }
        else if (map.containsKey("name")&& !StringUtils.isEmpty(map.get("name"))){
            sb.append("AND sre.`name` LIKE CONCAT('%',#{name},'%') ");
        }
        sb.append("ORDER BY sre.sort");
        return sb.toString();
    }
}
